<template>
  <div class="app-container">
    <el-card class="filter-container" shadow="never">
      <div>
        <i class="el-icon-search"></i>
        <span>筛选搜索</span>
        <el-button
          style="float: right"
          type="primary"
          @click="handleSearchList()"
          size="small"
        >
          查询搜索
        </el-button>
        <el-button
          style="float: right; margin-right: 15px"
          @click="handleResetSearch()"
          size="small"
        >
          重置
        </el-button>
      </div>
      <div style="margin-top: 15px">
        <el-form :inline="true" size="small" label-width="140px">
          <el-form-item label="输入搜索：">
            <el-input
              class="input-width"
              placeholder="角色名称"
              clearable
            ></el-input>
          </el-form-item>
        </el-form>
      </div>
    </el-card>
    <el-card class="operate-container" shadow="never">
      <i class="el-icon-tickets"></i>
      <span>数据列表 </span>
      <el-button
        type="success"
        size="mini"
        icon="el-icon-plus"
        @click="dialogFormVisible = true"
        >添加</el-button
      >
    </el-card>

<!-- 规格列表 -->
     <el-table :data="specOptionList" style="width: 100%">
      <el-table-column prop="spec.id" label="规格ID"> </el-table-column>
      <el-table-column prop="spec.specName" label="规格名称"> </el-table-column>
      <el-table-column prop="optionName" label="规格选项"> </el-table-column>
      <el-table-column label="操作" width="180px;">
        <template slot-scope="scope">
          <el-button
            @click="updatebrand(scope.row)"
            type="primary"
            size="mini"
            icon="el-icon-edit"
            >修改</el-button
          >
          <el-button
            @click="Idlist.push(scope.row.id),delbrand()"
            type="danger"
            size="mini"
            icon="el-icon-delete"
            >删除</el-button
          >
        </template>
      </el-table-column>
    </el-table>
    <span @click="(page = p), search()" 
    :key="index" 
    v-for="(p, index) in pages"
      >[{{ p }}]</span
    >
    <br />
    <!-- 显示页数导航 -->
    <div style="float: right">
      <el-pagination
        @size-change="handleSizeChange"
        @current-change="handleCurrentChange"
        :current-page="searchMap.pageNum"
        :page-sizes="[5, 10, 15, 20]"
        :page-size="searchMap.pageSize"
        layout="total, sizes, prev, pager, next, jumper"
        :total="total"
      >
      </el-pagination>
    </div>

<!-- 添加规格 -->
    <el-dialog
      title="规格编辑"
      :visible.sync="dialogFormVisible"
      :close-on-click-modal="false"
    >
      <el-form>
        <el-form-item label="规格名称" label-width="100px">
          <el-input v-model="entity.specName"></el-input>
        </el-form-item>

        <el-button type="success" icon="el-icon-plus" @click="addOptions()"
          >添加规格选项</el-button
        >

        <el-table :data="entity.options" style="width: 100%">
          <el-table-column prop="date" label="规格选项名称">
            <template slot-scope="scope">
              <el-input
                v-model="entity.options[scope.$index].optionName"
              ></el-input>
            </template>
          </el-table-column>
          <el-table-column prop="address" label="操作">
            <template slot-scope="scope">
              <el-button
                type="primary"
                @click="delOpt(scope.$index)"
                icon="el-icon-delete"
                >删除</el-button
              >
            </template>
          </el-table-column>
        </el-table>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button @click="dialogFormVisible = false">取 消</el-button>
        <el-button type="primary" @click="saveSpec()">确 定</el-button>
      </div>
    </el-dialog>
  </div>
</template>


<script>
import { findspecpage ,save} from "@/api/goodSpec";
export default {
  data() {
    return {
      dialogFormVisible: false,
      entity: {
        options: [],
      },
      searchMap: {
        pageNum: "1",
        pageSize: "5",
        where: {
          optionName: "",
          spec: {
            specName: "",
          },
          specId: 0,
        },
      },
      specOptionList:[],
    };
  },
  methods: {
    search() {
        
        findspecpage(this.searchMap).then(res=>{
            // 赋值
          this.specOptionList=res.data;
      });
    },
    add(){

    },
    
  },
  created(){
      this.search();
  },
 
};
</script>